<template>
  <div>
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="流程名称" prop="flowName">
        <el-input
          v-model="queryParams.flowName"
          placeholder="请输入流程名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="applyStatusOpt">
        <el-select v-model="queryParams.applyStatusOpt" placeholder="请选择状态" clearable size="small">
          <el-option
            v-for="dict in applyStatusOptOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>

      <el-button type="primary" @click="handleAdd" style="float: right;" size="mini"
       v-hasPermi="['course:adjust:edit']">新建调课</el-button>

      <CreateDialog ref="createDialog" @refresh="getList"></CreateDialog>
      <ViewDialog ref="viewDialog" @refresh="getList"></ViewDialog>
    </el-form>

    <el-table v-loading="loading" :data="adjustList">
      <el-table-column label="编号"  prop="instanceId" align="center" width="60px"/>
      <el-table-column label="流程名称"  prop="flowName" :show-overflow-tooltip="true"/>
      <el-table-column label="创建用户"  prop="createBy" align="center" width="100px" :show-overflow-tooltip="true"/>
      <el-table-column label="创建时间"  prop="createTime"  width="140px" align="center"/>
      <el-table-column label="提交时间" align="center" prop="startTime"  width="140px" />
      <el-table-column label="流程状态" align="center" prop="flowStatusOpt" :formatter="flowStatusOptFormat" width="60px"/>
      <el-table-column label="结束时间" align="center" prop="endTime" width="140px" />
      <el-table-column label="操作" align="center" width="100">
        <template slot-scope="scope">
          <el-button
            v-if= "scope.row.flowStatusOpt=='uncommitted'"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['course:adjust:edit']"
          >修改</el-button>
          <el-button
            v-if= "scope.row.flowStatusOpt!='uncommitted'"
            size="mini"
            type="text"
            @click="handleView(scope.row)"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listAdjust, getAdjust, delAdjust, addAdjust, updateAdjust, exportAdjust } from "@/api/course/adjust";
import CreateDialog from "@/views/course/adjust/createDialog.vue";
import ViewDialog from "@/views/course/adjust/viewDialog.vue";

export default {
  name: "Adjust",
  components: {CreateDialog, ViewDialog},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 调课管理表格数据
      adjustList: [],
      // 申请状态字典
      applyStatusOptOptions: [],
      flowStatusOptOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("applyStatusOpt").then(response => {
      this.applyStatusOptOptions = response.data;
    });
    this.getDicts("flowStatusOpt ").then(response => {
      this.flowStatusOptOptions = response.data;
    });
  },
  methods: {
   // 领用状态字典翻译
   applyStatusOptFormat(row, column) {
     return this.selectDictLabel(this.applyStatusOptOptions, row.applyStatusOpt);
   },
   // 流程状态字典翻译
   flowStatusOptFormat(row, column) {
     return this.selectDictLabel(this.flowStatusOptOptions, row.flowStatusOpt);
   },
    /** 查询调课管理列表 */
    getList() {
      this.loading = true;
      listAdjust(this.queryParams).then(response => {
        this.adjustList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.open = true;
      this.$refs["createDialog"].handleAdd();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.open = true;
      this.$refs["createDialog"].handleUpdate(row);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const instanceIds = row.instanceId || this.ids;
      this.$confirm('是否确认删除调课管理编号为"' + instanceIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delAdjust(instanceIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    handleView(row) {
      this.open = true;
      this.$refs["viewDialog"].handleUpdate(row);
    }
  }
};
</script>
